package com.ecar.api.aop;

import org.codehaus.jackson.map.DeserializationConfig;
import org.codehaus.jackson.map.ObjectMapper;
import org.codehaus.jackson.map.ser.impl.SimpleFilterProvider;

import javax.ws.rs.ext.ContextResolver;
import javax.ws.rs.ext.Provider;

@Provider
public class JerseyObjectMapperProvider implements ContextResolver<ObjectMapper> {

	private final ObjectMapper mapper;

	public JerseyObjectMapperProvider() {
		mapper = new ObjectMapper();
	}

	@Override
	public ObjectMapper getContext(Class<?> type) {
		mapper.configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false);
		SimpleFilterProvider sp = new SimpleFilterProvider();
		sp.setFailOnUnknownId(false);
		mapper.setFilters(sp);
		return mapper;
	}
}